{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content">
				<div class="row row-lg">
					<div class="col-sm-12">
						<div class="row" id="searchGroup">
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">昵称</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="nickname" placeholder="昵称" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">手机号</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="phone" placeholder="手机号" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">状态</button>
									</div>
									<select class="form-control" id="status">
										<option value="">请选择</option>
										<option value="1">正常</option>
										<option value="0">拉黑</option>
									</select>
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">是否红娘</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="is_matchmaker" placeholder="是否红娘" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">是否会员</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="is_vip" placeholder="是否会员" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">会员卡号</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="vip_number" placeholder="会员卡号" />
								</div>
							</div>
							<!-- search end -->
							<div class="col-sm-1">
								<button type="button" class="btn btn-success " onclick="CodeGoods.search()" id="">
									<i class="fa fa-search"></i>&nbsp;搜索
								</button>
							</div>
						</div>
						<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">
						<!--lwx 添加用户-->
						{if condition="in_array('backend/Member/add',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<button type="button" id="add" class="btn btn-primary button-margin" onclick="CodeGoods.add()">
							<i class="fa fa-plus"></i>&nbsp;添加
						</button>
						{/if}

						{if condition="in_array('backend/Member/update',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<button type="button" id="update" class="btn btn-success button-margin" onclick="CodeGoods.update()">
						<i class="fa fa-pencil"></i>&nbsp;修改
						</button>
						{/if}

						{if condition="in_array('backend/Member/delete',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<button type="button" id="delete" class="btn btn-danger button-margin" onclick="CodeGoods.delete()">
							<i class="fa fa-pencil"></i>&nbsp;删除
						</button>
						{/if}


						{if condition="in_array('backend/Member/import',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<button type="button" id="import" class="btn btn-primary button-margin" >
							导入
						</button>
						{/if}
						{if condition="in_array('backend/Member/import',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<a type="button" class="btn btn-primary button-margin" target="_blank" href="__PUBLIC__/static/excel/用户导入模板.xls">
							下载导入模板
						</a>
						{/if}

							<a type="button" class="btn btn-primary button-margin" target="_blank" href="export">
							导出
						</a>


						</div>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};
	layui.use(['form', 'upload','layer'], function () {
		var upload = layui.upload;
		var layer = layui.layer

		var uploadInst = upload.render({
			elem: '#import' //绑定元素
			,accept: 'file'
			,exts:'xls'
			,url: Feng.ctxPath + "/Member/import" //上传接口
			,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
				layer.load(); //上传loading
			}
			,done: function(data){
				layer.closeAll('loading'); //关闭loading
				//上传完毕回调
				if ('00' === data.status) {
					if(data.exist.length == 0) {
						Feng.success(data.msg, 5000);
					} else {
						Feng.success(data.msg+','+data.exist.join(',')+'是现有用户，对应的资料导入失败！', 5000);
					}
					CodeGoods.table.refresh();
				} else {
					Feng.error(data.msg + "！", 1000);
				}
			}
			,error: function(data){
				console.log(data);
				layer.closeAll('loading'); //关闭loading
				//请求异常回调
			}
		});
	});

	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
 			{title: '编号', field: 'uid', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '昵称', field: 'nickname', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '头像', field: 'avatar', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.avatarFormatter},
 			{title: '余额', field: 'balance', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '手机号', field: 'phone', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '照片', field: 'pic', visible: false, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.picFormatter},
 			//{title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.statusFormatter},
			{title: '上级红娘', field: 'matchmaker_id', visible: true, align: 'center', valign: 'middle',sortable: true},
			{title: '用户注册时间', field: 'create_time', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.createtimeFormatter},
			/*{title: '置顶卡名称', field: 'top_card_name', visible: true, align: 'center', valign: 'middle',sortable: true},
			{title: '置顶卡有效期', field: 'top_card_expiry', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.createtimeFormatter},*/
 			{title: '是否红娘', field: 'is_matchmaker', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.is_matchmakerFormatter},
 			{title: '是否会员', field: 'is_vip', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.is_vipFormatter},
			{title: '是否家长', field: 'is_parent', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.is_parentFormatter},
            {title: '是否认证', field: 'is_auth', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.is_authFormatter},
            {title: '审核状态', field: 'auth_status', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.auth_statusFormatter},
 			{title: '操作', field: '', visible: true, align: 'center', valign: 'middle',formatter: 'CodeGoods.buttonFormatter'},
 		];
 	};

	CodeGoods.createtimeFormatter = function(value,row,index) {
		if(value){
			return formatDateTime(value,'Y-m-d H:i:s');
		}
	}

	CodeGoods.buttonFormatter = function(value,row,index) {
		if(row.uid){
			var str= '';
			{if condition="in_array('backend/Member/view',session('backend.nodes')) || session('backend.role_id') eq 1"}
			str += '<button type="button" class="btn btn-info btn-xs" title="查看详情"  onclick="CodeGoods.view('+row.uid+')"><i class="fa fa-eye"></i>&nbsp;查看详情</button>&nbsp;';
			{/if}
			{if condition="in_array('backend/Member/update',session('backend.nodes')) || session('backend.role_id') eq 1"}
			str += '<button type="button" class="btn btn-success btn-xs" title="修改"  onclick="CodeGoods.update('+row.uid+')"><i class="fa fa-pencil"></i>&nbsp;修改</button>&nbsp;';
			{/if}
			{if condition="in_array('backend/Member/delete',session('backend.nodes')) || session('backend.role_id') eq 1"}
			str += '<button type="button" class="btn btn-danger btn-xs" title="删除"  onclick="CodeGoods.delete('+row.uid+')"><i class="fa fa-pencil"></i>&nbsp;删除</button>&nbsp;';
			{/if}
			return str;
		}
	}

	CodeGoods.avatarFormatter = function(value,row,index) {
		if(value){
			return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";
		}
	}

	CodeGoods.picFormatter = function(value,row,index) {
		if(value){
			return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";
		}
	}
    CodeGoods.is_matchmakerFormatter = function(value,row,index) {
        if(value){
            return '<span class="btn btn-success">' + '是' + '</span>';
        }else{
            return '<span class="btn btn-warning">' + '否' + '</span>';
        }
    }

	CodeGoods.is_parentFormatter = function(value,row,index) {
		if(value){
			return '<span class="btn btn-success">' + '是' + '</span>';
		}else{
			return '<span class="btn btn-warning">' + '否' + '</span>';
		}
	}

    CodeGoods.is_authFormatter = function(value,row,index) {
        if(value){
            return '<span class="btn btn-success">' + '是' + '</span>';
        }else{
            return '<span class="btn btn-warning">' + '否' + '</span>';
        }
    }

    CodeGoods.is_vipFormatter = function(value,row,index) {
        if(value){
            return '<span class="btn btn-success">' + '是' + '</span>';
        }else{
            return '<span class="btn btn-warning">' + '否' + '</span>';
        }
    }

	CodeGoods.statusFormatter = function(value,row,index) {
		if(value !== null){
			if(value == 1){
				return '<input class="mui-switch mui-switch-animbg status'+row.uid+'" type="checkbox" onclick="CodeGoods.updatestatus('+row.uid+',0,\'status\')" checked>';
			}else{
				return '<input class="mui-switch mui-switch-animbg status'+row.uid+'" type="checkbox" onclick="CodeGoods.updatestatus('+row.uid+',1,\'status\')">';
			}
		}
	}


	CodeGoods.updatestatus = function(pk,value,field) {
		var ajax = new $ax(Feng.ctxPath + "/Member/updateExt", function (data) {
			if ('00' !== data.status) {
				Feng.error(data.msg);
				$("."+field+pk).prop("checked",!$("."+field+pk).prop("checked"));
			}
		});
		var val = $("."+field+pk).prop("checked") ? 1 : 0;
		ajax.set('uid', pk);
		ajax.set('status', val);
		ajax.start();
	}

    CodeGoods.auth_statusFormatter = function(value,row,index) {
        if(value == 1){
            return '<span class="btn btn-success">' + '待审核' + '</span>';
        }else if(value == 2) {
            return '<span class="btn btn-warning">' + '通过' + '</span>';
        }else if(value == 3) {
            return '<span class="btn btn-warning">' + '已拒绝' + '</span>';
        }
    }

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['offset'] = 0;
		queryData['nickname'] = $("#nickname").val();
		queryData['phone'] = $("#phone").val();
		queryData['status'] = $("#status").val();
		queryData['is_matchmaker'] = $("#is_matchmaker").val();
		queryData['is_vip'] = $("#is_vip").val();
		queryData['vip_number'] = $("#vip_number").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.view = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Member/view?uid='+value});
			if(!IsPC()){layer.full(index)}
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.uid;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Member/view?uid='+idx});
				this.layerIndex = index;
				if(!IsPC()){layer.full(index)}
			}
		}
	}


	CodeGoods.update = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '修改',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Member/update?uid='+value});
			if(!IsPC()){layer.full(index)}
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.uid;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '修改',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Member/update?uid='+idx});
				this.layerIndex = index;
				if(!IsPC()){layer.full(index)}
			}
		}
	}


			CodeGoods.delete = function (value) {
				if(value){
					Feng.confirm("是否删除选中项？", function () {
						var ajax = new $ax(Feng.ctxPath + "/Member/delete", function (data) {
							if ('00' === data.status) {
								Feng.success(data.msg);
								CodeGoods.table.refresh();
							} else {
								Feng.error(data.msg);
							}
						});
						ajax.set('uid', value);
						ajax.start();
					});
				}else{
					if (this.check()) {
						var idx = '';
						$.each(CodeGoods.seItem, function() {
							idx += ',' + this.uid;
						});
						idx = idx.substr(1);
						Feng.confirm("是否删除选中项？", function () {
							var ajax = new $ax(Feng.ctxPath + "/Member/delete", function (data) {
								if ('00' === data.status) {
									Feng.success(data.msg,1000);
									CodeGoods.table.refresh();
								} else {
									Feng.error(data.msg,1000);
								}
							});
							ajax.set('uid', idx);
							ajax.start();
						});
					}
				}
			}

	//lwx 添加用户

	CodeGoods.add = function (value) {
		var url = location.search;
		var index = layer.open({type: 2,title: '添加',area: ['800px', '500px'],fix: false, maxmin: true,content: Feng.ctxPath + '/Member/add'+url});
		this.layerIndex = index;
		if(!IsPC()){layer.full(index)}
	}

	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/Member/index"+url,defaultColunms,20);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});


</script>
{/block}